#ifndef GENERIC_FRESNEL_COS_H
#define GENERIC_FRESNEL_COS_H
#include "kernel_tensor.h"
namespace AscendC {
constexpr float CN[] = {
    -4.98843114573573548651E-8, 9.50428062829859605134E-6,
    -6.45191435683965050962E-4, 1.88843319396703850064E-2,
    -2.05525900955013891793E-1, 9.99999999999999998822E-1,
};
constexpr float CD[] = {
    3.99982968972495980367E-12, 9.15439215774657478799E-10,
    1.25001862479598821474E-7,  1.22262789024179030997E-5,
    8.68029542941784300606E-4,  4.12142090722199792936E-2,
    1.00000000000000000118E0,
};
__aicore__ inline void GenericFresnelCos(const LocalTensor<float>& dst, const LocalTensor<float>& src,
    const LocalTensor<float>& tmp1, const LocalTensor<float>& tmp2, const uint32_t length)
{
    Mul(tmp1, src, src, length);
    Mul(tmp1, tmp1, tmp1, length); 
    Muls(tmp2, tmp1, CN[0], length);
    Adds(tmp2, tmp2, CN[1], length);
    Mul(tmp2, tmp2, tmp1, length);
    Adds(tmp2, tmp2, CN[2], length);
    Mul(tmp2, tmp2, tmp1, length);
    Adds(tmp2, tmp2, CN[3], length);
    Mul(tmp2, tmp2, tmp1, length);
    Adds(tmp2, tmp2, CN[4], length);
    Mul(tmp2, tmp2, tmp1, length);
    Adds(tmp2, tmp2, CN[5], length);
    Mul(dst, tmp2, src, length);
    Muls(tmp2, tmp1, CD[0], length);
    Adds(tmp2, tmp2, CD[1], length);
    Mul(tmp2, tmp2, tmp1, length);
    Adds(tmp2, tmp2, CD[2], length);
    Mul(tmp2, tmp2, tmp1, length);
    Adds(tmp2, tmp2, CD[3], length);
    Mul(tmp2, tmp2, tmp1, length);
    Adds(tmp2, tmp2, CD[4], length);
    Mul(tmp2, tmp2, tmp1, length);
    Adds(tmp2, tmp2, CD[5], length);
    Mul(tmp2, tmp2, tmp1, length);
    Adds(tmp2, tmp2, CD[6], length);
    Div(dst, dst, tmp2, length);
}
}
#endif